package cn.net.susan.controller.web;


import cn.net.susan.annotation.NoLogin;
import cn.net.susan.entity.sys.AuthUserEntity;
import cn.net.susan.entity.sys.JwtUserEntity;
import cn.net.susan.entity.sys.TokenEntity;
import cn.net.susan.entity.user.CaptchaEntity;
import cn.net.susan.service.sys.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 给前端用户用的接口
 */
@Api(tags="Web用户操作",description = "Web用户接口")
@RestController
@RequestMapping("/v1/web/user")
@Validated
public class WebUserController {
    @Autowired
    private UserService userService;

    /**
     * 用户登录
     */
    @NoLogin
    @ApiOperation(notes="用户登录",value = "用户登录")
    @PostMapping("/login")
    public TokenEntity login(@Valid @RequestBody AuthUserEntity authUserEntity){
        return userService.login(authUserEntity);
    }

    /**
     * 用户退出登录
     * @param request 请求
     * HttpServletRequest 是 Java Servlet 规范中的核心接口，用于封装客户端发送的 HTTP 请求信息
     */
    @NoLogin
    @ApiOperation(notes = "用户退出登录",value = "用户退出登录")
    @PostMapping("logout")
    public void logout(HttpServletRequest request){
        //return userService.login(request);
    }

    @NoLogin
    @ApiOperation("获取用户信息")
    @GetMapping(value = "/info")
    public JwtUserEntity getUserInfo(){
        return userService.getUserInfo();
    }

    @NoLogin
    @ApiOperation("获取验证码")
    @GetMapping(value = "/code")
    public CaptchaEntity getCode() {
        return userService.getCode();
    }

}
